package com.beiding.jsonanalyzer.querylink;

import com.beiding.jsonanalyzer.flow.BranchNode;
import com.beiding.jsonanalyzer.flow.FlushEvent;
import com.beiding.jsonanalyzer.flow.ValueNode;
import com.beiding.jsonanalyzer.flow.flowevents.BatchEndEvent;
import com.beiding.jsonanalyzer.flow.flowevents.BatchStartEvent;
import com.beiding.jsonanalyzer.flow.flowevents.DataNodeEvent;

/**
 * 中继计算节点
 *
 * @author 丁常磊
 * @date 2022/5/13 10:41
 */

public class ComputeNodeUtils {

    public static <W> void bindControlEvent(BranchNode<W> from, BranchNode<W> to) {

        //绑定处理流事件外的其他所有事件
        from.onDataEvent(BatchStartEvent.eventType(), to::signDataEvent);
        from.onDataEvent(BatchEndEvent.eventType(), to::signDataEvent);
        bindBaseEvent(from, to);
    }

    public static <W> void bindDataEvent(BranchNode<W> from, BranchNode<W> to) {
        from.onDataEvent(DataNodeEvent.eventType(), to::signDataEvent);
    }

    public static <W> void bindBaseEvent(BranchNode<W> from, BranchNode<W> to) {
        from.onDataEvent(FlushEvent.type(), to::signDataEvent);
    }

}
